package com.situ.mall.web.controller;

import com.situ.mall.common.service.ICartService;
import com.situ.mall.web.annotation.MyLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private ICartService cartService;

    @GetMapping("/list")
    public String page(Model model){
        model.addAttribute("carts",cartService.cartList());
        return "cart";
    }

    @MyLog
    @PostMapping("/save")
    @ResponseBody
    public void save(Integer pId) {
        cartService.addToCart(pId);
    }
}
